package com.yudaxian.common.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private Integer code;

    private String message;

    private T Data;

    /**
     * 成功
     * @return
     * @param <T>
     */
    //只返回前两个
    public static<T> Result<T> success() {
        return new Result<>(20000, "success", null);
    }

    //把数据也返回
    public static<T> Result<T> success(T data) {
        return new Result<>(20000, "success", data);
    }

    //传消息和数据
    public static<T> Result<T> success(T data, String msg) {
        return new Result<>(20000, msg, data);
    }

    //只传消息
    public static<T> Result<T> success(String msg) {
        return new Result<>(20000, msg, null);
    }

    /**
     * 失败的
     */
    //只返回前两个
    public static <T> Result<T> fail() {
        return new Result<>(20001, "fail", null);
    }

    //把数据也返回
    public static <T> Result<T> fail(Integer code) {
        return new Result<>(code, "fail", null);
    }

    //传消息和数据
    public static <T> Result<T> fail(Integer code, String msg) {
        return new Result<>(code, msg, null);
    }

    //只传消息
    public static <T> Result<T> fail(String msg) {
        return new Result<>(20001, msg, null);
    }
}
